import request from '@/utils/request'

/**
 * 获取所用频道
 * @returns Promise对象
 */
export const getAllChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}

/**
 * 发送登录请求
 * @param {*} data {mobile: 手机号, code: 验证码}
 * @returns Promise对象
 */
export const loginAPI = (data) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}

/**
 * 获取用户已选频道
 * @returns Promise对象
 */
export const getUserChannelListAPI = () => {
  return request({
    url: '/v1_0/user/channels'
  })
}

/**
 * 获取所有文章列表
 * @param {*} param0 {channel_id: 频道id, timestamp: 时间戳，上一段文章中最后一个文章的时间戳, 用于获取下一页数据}
 * @returns
 */
export const getArticleListAPI = ({ channel_id, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id,
      timestamp
    }
  })
}

/**
 * 反馈-不感兴趣
 * @param {*} data 文章id
 * @returns Promise对象
 */
export const articleDislikeAPI = (artId) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: artId
    }
  })
}

/**
 * 反馈-举报文章
 * @param {*} param0 { artId：文章id, type：文章举报类型, remark：其他问题说明 }
 * @returns
 */
export const reportArticleAPI = ({ artId, type, remark }) => {
  const dataObj = {
    target: artId,
    type
  }
  if (type === 0) {
    dataObj.remark = remark
  }
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: dataObj
  })
}

/**
 * 设置频道列表
 * @param {*} param0 [{id: 频道id, seq: 频道索引}]
 * @returns Promise对象
 */
export const uploadUserChannelAPI = ({ channels }) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels
  }
})
